package com.ysd.lis.controller.sys;


import cn.hutool.core.bean.BeanUtil;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.SysMenu;
import com.ysd.lis.request.menuAddParam;
import com.ysd.lis.service.SysMenuService;
import com.ysd.lis.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * cold_chain.t_menu 前端控制器
 * </p>
 *
 * @author Peng
 * @since 2021-10-12
 */
@Api(tags = "菜单管理")
@RestController
public class SysMenuController extends BaseController {

    @Autowired
    SysMenuService sysMenuService;
    @Autowired
    SysRoleService sysRoleService;

    @ApiOperation("获取菜单树")
    @GetMapping("/api/sys/menuList")
    public Result menuList(SysMenu sysMenu){
        return sysMenuService.findMenuList(sysMenu);
    }

    @ApiOperation("获取菜单时报表类型的数据集")
    @GetMapping("/api/sys/getMenuListByType")
    public Result getMenuListByType(SysMenu sysMenu){
        return sysMenuService.getMenuListByType(sysMenu);
    }


    @ApiOperation("添加菜单")
    @PostMapping("/api/sys/addMenu")
    @LogDetail(requestParam ="addMenu",operationType = OperationType.INSERT, module = "菜单管理",content = "新增菜单操作")
    public Result addMenu(@RequestBody menuAddParam menu){
        SysMenu sysMenu = new SysMenu();
        BeanUtil.copyProperties(menu, sysMenu);
        return sysMenuService.addMenu(sysMenu);
    }

    @ApiOperation("修改菜单")
    @PostMapping("/api/sys/editMenu")
    @LogDetail(requestParam ="editMenu",operationType = OperationType.UPDATE, module = "菜单管理",content = "修改菜单操作")
    public Result editMenu(@RequestBody menuAddParam menu){
        SysMenu sysMenu = new SysMenu();
        BeanUtil.copyProperties(menu, sysMenu);
        return sysMenuService.editMenu(sysMenu);
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/api/sys/deleteMenu/{id}")
    @LogDetail(requestParam ="deleteMenu",operationType = OperationType.DELETE, module = "菜单管理",content = "删除菜单操作")
    public Result deleteMenu(@PathVariable("id") String id){
        return sysMenuService.deleteMenu(id);
    }

    @ApiOperation("获取模块与菜单树形结构")
    @GetMapping("/api/sys/getModuleAndMenuList")
    public Result getModuleAndMenuList(SysMenu menu) {
        return sysMenuService.getModuleAndMenuList(menu);
    }

}
